const { stuModel,seriesModel } = require('../../model/index');
const {getResultToObject } =require('../../services/utils');
module.exports = {
  list: async (req,res) => {
    let scratchOrPython;
    const { type = 'scratch' } = req.params;
    const { org, learn_number } = req.decode;
    const series_attr = ['id', 'order', 'name'];
    type === 'scratch' ? scratchOrPython = 1 : scratchOrPython = 2;
    try {
      const student_series = await stuModel.findByRelation(['org'], { org: org, learn_number: learn_number }, {
        model: seriesModel.getModel(), attributes: series_attr, where: { type: scratchOrPython }});

      const list = getResultToObject(student_series, 'series', series_attr);
      res.send({
        status: 0,
        data: {
          items: list,
          total: list.length
        }
      })
    } catch (e) {console.log(e)}
  }
};
